package com.cadre.common.utils.oldutil;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/* loaded from: AgeUtil.class */
public class AgeUtil {
    public static int getAgeFromBirthTime(String birthTimeString) {
        String[] strs = birthTimeString.trim().split("-");
        int selectYear = Integer.parseInt(strs[0]);
        int selectMonth = Integer.parseInt(strs[1]);
        Calendar cal = Calendar.getInstance();
        int yearNow = cal.get(1);
        int monthNow = cal.get(2) + 1;
        int yearMinus = yearNow - selectYear;
        int monthMinus = monthNow - selectMonth;
        int age = yearMinus;
        if (yearMinus < 0) {
            age = 0;
        } else if (yearMinus == 0) {
            if (monthMinus < 0) {
                age = 0;
            } else if (monthMinus != 0 && monthMinus > 0) {
                age = 1;
            }
        } else if (yearMinus > 0) {
            if (monthMinus < 0) {
                age--;
            } else if (monthMinus != 0 && monthMinus > 0) {
            }
        }
        return age;
    }

    public static int getAgeFromBirthTime(long birthTimeLong) {
        return getAgeFromBirthTime(new SimpleDateFormat("yyyy-MM-dd").format(new Date(birthTimeLong * 1000)));
    }

    public static int getAgeFromBirthTime(Date date) {
        return getAgeFromBirthTime(new SimpleDateFormat("yyyy-MM-dd").format(date));
    }

    public static int getCurrentAge(Date birthday) {
        Calendar curr = Calendar.getInstance();
        Calendar born = Calendar.getInstance();
        born.setTime(birthday);
        int age = curr.get(1) - born.get(1);
        if (age <= 0) {
            return 0;
        }
        int currMonth = curr.get(2);
        int currDay = curr.get(5);
        int bornMonth = born.get(2);
        if (currMonth < bornMonth || (currMonth == bornMonth && currDay <= born.get(5))) {
            age--;
        }
        if (age < 0) {
            return 0;
        }
        return age;
    }
}
